package com.fbty.mt.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;

import com.fbty.base.dao.MtJdbcDao;
import com.fbty.mt.dao.UserDao;
import com.fbty.mt.domain.User;
import com.fbty.mt.service.LoginService;
import com.fbty.mt.utils.DegistUtil;
/**
 * 用户登陆服务类
 * @author thinkpad
 *
 */
public class LoginServiceImpl implements LoginService{
	private MtJdbcDao mtJdbcDao;
	private UserDao userDao;
	/**
	 * 查询数据库里是否存在这个用户
	 */
	@Override
	public List findUsername(String username) {
		String hql = " from com.fbty.mt.domain.User where username=?";
		Query query = userDao.createQuery(hql, username);
		return query.list();
	}
	/**
	 * 验证密码是否正确
	 */
	@Override
	public List<User> findUsernamePassword(String username, String password) {
		String hql = " from User where username= ? and password= ?";
		Query query = userDao.createQuery(hql, username,DegistUtil.md5Digest(password));
		
		return query.list();
	}
	/**
	 * 验证注册用户是否存在
	 * @param loginname
	 * @return
	 */
	@Override
	public boolean validLogin(String loginname) {
		String hql = " from com.fbty.mt.domain.User u where u.username=:username";
		Map<String, String> map = new HashMap<String,String>();
		map.put("username", loginname);
		List list = userDao.find(hql,map);
		if(list.size() > 0) {
			return false;
		} else {
			return true;
		}
	}
	public MtJdbcDao getMtJdbcDao() {
		return mtJdbcDao;
	}
	public void setMtJdbcDao(MtJdbcDao mtJdbcDao) {
		this.mtJdbcDao = mtJdbcDao;
	}
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	
	
}
